package com.liao.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liao.bean.Order;
import com.liao.bean.result.Msg;
import com.liao.bean.result.PageResult;
import com.liao.dao.OrderDao;
import com.liao.dao.UserDao;
import com.liao.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderDao orderDao;

    @Override
    public PageResult<Order> queryModuleListByPage(Integer currentPage, Integer pageSize, String state_id, String orderId) throws Exception {

        PageHelper.startPage(currentPage,pageSize);
        HashMap<String,Object> map = new HashMap<>();
        map.put("state_id",state_id);
        map.put("orderId",orderId);
        List<Order> orderList = orderDao.selectOrderListLikeRoleName(map);
        PageInfo<Order> pageInfo = new PageInfo<>(orderList);
        return new PageResult<>(0, Msg.ORDER_QUERY_SUCCESS,pageInfo.getTotal(),pageInfo.getList());
    }

    @Override
    public void addOrder(String orderId, String buyerPhone, String orderTime, String state, String userId, String address) throws Exception {
        HashMap<String,Object> map = new HashMap<>();
        map.put("state",state);
        map.put("orderId",orderId);
        map.put("buyerPhone",buyerPhone);
        map.put("orderTime",orderTime);
        map.put("userId",userId);
        map.put("address",address);
        orderDao.addOrder(map);
    }

    @Override
    public void deleteOrder(String orderId) throws Exception {
        orderDao.deleteOrder(orderId);
    }

    @Override
    public void editOrder(String oldOrderId, String orderId, String buyerPhone, Date orderTime, String state, String userId, String address) throws Exception {
        HashMap<String,Object> map = new HashMap<>();
        map.put("oldOrderId",oldOrderId);
        map.put("state",state);
        map.put("orderId",orderId);
        map.put("buyerPhone",buyerPhone);
        map.put("orderTime",orderTime);
        map.put("userId",userId);
        map.put("address",address);
        orderDao.updateOrder(map);
    }
}
